import cv2
path="GREEN.mp4"
cap=cv2.VideoCapture(path)
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
print(frame_count)
def Get_565(bgr):
    b,g,r=bgr
    r,g,b=r&0xf8,g&0xfc,b&0xf8
    res=(r<<8)|(g<<3)|(b>>3)
    return res
count=0
same_count=0
img_count=0
array_count=0
buffer=[]
with open("dst.txt",'w') as f:
    while True:
        ret, img = cap.read()
        if not ret:
            break
        else:
            # frame=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY).copy()
            frame=cv2.resize(img,(120,120))
            frame=frame[25:75,15:105]
            if(count%7==0):
                img_count+=1
                cv2.imshow("win",frame)
                for i in range(50):
                    for j in range(90):
                        buffer.append(Get_565(frame[i,j]))
                        f.write(hex(Get_565(frame[i,j]))+",")
                        array_count+=1
                        if(array_count%16==0):
                            f.write("\n")
        
        input_c=cv2.waitKey(1)& 0xff
        if(input_c==ord("q")):
            break
        count+=1
cap.release()

print(count,img_count)
cv2.destroyAllWindows()